package com.wg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wg.R;
import com.wg.entity.Focus;
import com.wg.entity.dto.FocusDto;
import com.wg.mapper.FocusMapper;
import com.wg.service.FocusService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FocusServiceImpl extends ServiceImpl<FocusMapper, Focus> implements FocusService {
    @Override
    public Page<Focus> selectByUserId(Integer userId, Integer pageSize, Integer pageNum) {
        LambdaQueryWrapper<Focus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Focus::getUserId, userId);
        wrapper.select(Focus::getId, Focus::getWgId);
        Page<Focus> focusPage = new Page<>(pageNum, pageSize);
        page(focusPage, wrapper);
        return focusPage;
    }

    @Override
    public List<Focus> getFocusByWg(Long id) {
        LambdaQueryWrapper<Focus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Focus::getWgId, id);
        return list(wrapper);
    }

    @Override
    public R addFocus(FocusDto focus) {
        Focus fo = new Focus();
        fo.setUserId(focus.getUserId()).setWgId(focus.getWgId());
        save(fo);
        return R.ok();
    }

    @Override
    public R deleteFocus(FocusDto focus) {
        LambdaQueryWrapper<Focus> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Focus::getUserId, focus.getUserId()).eq(Focus::getWgId, focus.getWgId());
        remove(wrapper);
        return R.ok();
    }
}
